package cn.chinaflame.pagodas.entity;

import cn.chinaflame.pagodas.schedul.PaBalmOrderFailure;
import cn.chinaflame.pagodas.schedul.PaOrderFailure;
import cn.chinaflame.pagodas.schedul.PaOrderSchedule;
import cn.chinaflame.pagodas.utils.ScheduleTime;

import java.math.BigDecimal;
import java.util.Objects;

import javax.persistence.*;

/**
* @author    created by lbq
* @date	     2018年7月24日 上午11:10:50
**/
@Entity
@Table(name = "pa_balm_order", schema = "pagoda", catalog = "")
public class PaBalmOrder {

    private String id;          //编号
    private String mobile;      //手机号
    private String openid;      //openinid
    private String goodsId;     //随缘捐赠商品ID
    private BigDecimal money;   //金额
    private String orderType;   //订单类型。1为香油钱订单，2为随缘捐赠订单
    private String payType;
    private String payStatus;   //支付状态，0-未支付，1-支付中。2-支付完成，3-支付失败，4-交易超时
    private String serialNumber;
    private String errorMsg;
    private String orderId;
    private String addTime;
    private String payTime;
    private String payFinishTime;
    private String createtime;
    private String updatetime;
    private ScheduleTime time;

    @Id
    @Column(name = "id", nullable = false, length = 20)
    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    @Basic
    @Column(name = "mobile", nullable = true, length = 20)
    public String getMobile() {
        return mobile;
    }

    public void setMobile(String mobile) {
        this.mobile = mobile;
    }

    @Basic
    @Column(name = "openId", nullable = true, length = 50)
    public String getOpenid() {
        return openid;
    }

    public void setOpenid(String openid) {
        this.openid = openid;
    }

    @Basic
    @Column(name = "goods_id",nullable = true, length = 20)
    public String getGoodsId() {
        return goodsId;
    }

    public void setGoodsId(String goodsId) {
        this.goodsId = goodsId;
    }

    @Basic
    @Column(name = "money", nullable = true, precision = 2)
    public BigDecimal getMoney() {
        return money;
    }

    public void setMoney(BigDecimal money) {
        this.money = money;
    }

    @Basic
    @Column(name = "order_type",nullable = true,length = 2)
    public String getOrderType() {
        return orderType;
    }

    public void setOrderType(String orderType) {
        this.orderType = orderType;
    }

    @Basic
    @Column(name = "pay_type", nullable = true, length = 10)
    public String getPayType() {
        return payType;
    }

    public void setPayType(String payType) {
        this.payType = payType;
    }

    @Basic
    @Column(name = "pay_status", nullable = true, length = 10)
    public String getPayStatus() {
        return payStatus;
    }

    public void setPayStatus(String payStatus) {
        this.payStatus = payStatus;
    }
    

    @Basic
    @Column(name = "serial_number", nullable = true, length = 40)
    public String getSerialNumber() {
        return serialNumber;
    }

    public void setSerialNumber(String serialNumber) {
        this.serialNumber = serialNumber;
    }
    

    @Basic
    @Column(name = "error_msg", nullable = true, length = 100)
    public String getErrorMsg() {
        return errorMsg;
    }

    public void setErrorMsg(String errorMsg) {
        this.errorMsg = errorMsg;
    }

    
	@Basic
    @Column(name = "order_id", nullable = true,length=20)
    public String getOrderId() {
		return orderId;
	}

	public void setOrderId(String orderId) {
		this.orderId = orderId;
	}

	@Basic
    @Column(name = "add_time", nullable = true)
    public String getAddTime() {
        return addTime;
    }

    public void setAddTime(String addTime) {
        this.addTime = addTime;
    }

    @Basic
    @Column(name = "pay_time", nullable = true)
    public String getPayTime() {
        return payTime;
    }

    public void setPayTime(String payTime) {
        this.payTime = payTime;
    }

    @Basic
    @Column(name = "pay_finish_time", nullable = true)
    public String getPayFinishTime() {
        return payFinishTime;
    }

    public void setPayFinishTime(String payFinishTime) {
        this.payFinishTime = payFinishTime;
    }

    @Basic
    @Column(name = "createtime", nullable = true)
    public String getCreatetime() {
        return createtime;
    }

    public void setCreatetime(String createtime) {
        this.createtime = createtime;
    }

    @Basic
    @Column(name = "updatetime", nullable = true)
    public String getUpdatetime() {
        return updatetime;
    }

    public void setUpdatetime(String updatetime) {
        this.updatetime = updatetime;
    }

    @Transient
    public ScheduleTime getTime() {
        return time;
    }

    public void setTime(ScheduleTime time) {
        this.time = time;
    }

    public PaBalmOrder () {}

    public PaBalmOrder (String id, ScheduleTime scheduleTime, String status) {
        setId(id);
        this.payStatus = status;
        PaOrderSchedule.getInstance().startTask(new PaBalmOrderFailure(this),scheduleTime);
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        PaBalmOrder paBalmOrder = (PaBalmOrder) o;
        return Objects.equals(id, paBalmOrder.id) &&
                Objects.equals(money, paBalmOrder.money) &&
                Objects.equals(payType, paBalmOrder.payType) &&
                Objects.equals(payStatus, paBalmOrder.payStatus) &&
                Objects.equals(serialNumber, paBalmOrder.serialNumber) &&
                Objects.equals(errorMsg, paBalmOrder.errorMsg) &&
                Objects.equals(orderId, paBalmOrder.orderId) &&
                Objects.equals(addTime, paBalmOrder.addTime) &&
                Objects.equals(payTime, paBalmOrder.payTime) &&
                Objects.equals(payFinishTime, paBalmOrder.payFinishTime) &&
                Objects.equals(createtime, paBalmOrder.createtime) &&
                Objects.equals(updatetime, paBalmOrder.updatetime);
    }

    @Override
    public int hashCode() {

        return Objects.hash(id,  money,  payType, payStatus, serialNumber, errorMsg,   addTime, payTime, payFinishTime, createtime, updatetime);
    }

}
